﻿/*
 * @author: wizardc
 */

using Dou.UI;
using UnityEditor;
using UnityEngine;

namespace DouEditor.UI
{
    [CustomEditor(typeof(DToggleGroup), true)]
    [CanEditMultipleObjects]
    public class DToggleGroupEditor : Editor
    {
        [MenuItem("GameObject/DouUI/Toggle Group", false, 10)]
        private static void CreateUI(MenuCommand menuCommand)
        {
            var go = UIEditorUtil.CreateUIElement("Toggle Group");
            go.AddComponent<DToggleGroup>();
            UIEditorUtil.PlaceUIElementRoot(go, menuCommand);
        }
        
        private SerializedProperty _onChanged;
        
        private void OnEnable()
        {
            _onChanged = serializedObject.FindProperty("_onChanged");
        }
        
        public override void OnInspectorGUI()
        {
            var toggleGroup = (DToggleGroup) target;
            using (new GUILayout.VerticalScope())
            {
                toggleGroup.allowSwitchOff = EditorGUILayout.Toggle(new GUIContent("允许全不选"), toggleGroup.allowSwitchOff);
            }
            serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_toggles"));
            EditorGUILayout.PropertyField(_onChanged);
            serializedObject.ApplyModifiedProperties();
        }
    }
}
